package controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComponent;

import view.HomeEvent;

public class ActionHomeEvent implements ActionListener{


	@Override
	public void actionPerformed(ActionEvent e) {
		String b = ((JButton) e.getSource()).getName();
		switch (b){
		case "notify":{
			HomeEvent.showNotify();
			Engine.updateUnread(HomeEvent.idUnread);
			break;
		}
		case "closeNotify":{
			HomeEvent.closeNotify();
			HomeEvent.uppdater();
			Engine.updateUnread(HomeEvent.idUnread);
		}break;
		case "addEvent":{
			Engine.startCreateEvent();
			break;
		}
		case "delEvent":{
			int id = getId(e);
			Engine.delEvent(id);
			HomeEvent.uppdater();
			Engine.updateUnread(HomeEvent.idUnread);
			break;
		}
		case "modEvent":{
			int id = getId(e);
			Engine.startModifyEvent(id);
			HomeEvent.uppdater();
			Engine.updateUnread(HomeEvent.idUnread);
			break;
		}
		}
		((JComponent)e.getSource()).requestFocus();
	}

	public int getId(ActionEvent e){
		String name = ((JButton) e.getSource()).getComponent(0).getName();
		int id = Integer.valueOf(name);
		return id;
	}

}
